package com.lzy.demo;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import com.lzy.demo.base.BaseActivity;
import butterknife.Bind;
public class WebActivity extends BaseActivity {
public final static String URL = "url";
public final static String TITLE = "title";
@Bind(R.id.toolbar) Toolbar toolbar;
@Bind(R.id.pb) ProgressBar pb;
@Bind(R.id.webView) WebView webView;
public static void runActivity(Context context, String title, String url) {
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra(URL, url);
intent.putExtra(TITLE, title);
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
String url = getIntent().getStringExtra(URL);
String title = getIntent().getStringExtra(TITLE);
initToolBar(toolbar, true, title);
pb.setMax(100);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
pb.setProgress(newProgress);
if (newProgress >= 100) {
pb.setVisibility(View.GONE);
}
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl(url);
}
}